package com.mengniu.common.social.config.enums;

import com.mengniu.commerce.common.core.utils.SpringUtils;
import com.mengniu.common.social.config.properties.SocialLoginConfigProperties;
import com.mengniu.common.social.config.utils.AuthRedisStateCache;
import com.mengniu.common.social.mengniu98k.AuthMengniu98kRequest;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.request.*;

import java.util.function.Function;


/**
 * @Author: dgyu-398305246@qq.com
 * @createTime: 2023年12月06日 13:31:58
 * @version:工厂枚举function
 * @Description:
 */
public class AuthRequestFactory {

    private static final AuthRedisStateCache STATE_CACHE = SpringUtils.getBean(AuthRedisStateCache.class);

    public static final Function<SocialLoginConfigProperties, AuthRequest> megnniuFunction = (t) -> new AuthMengniu98kRequest(AuthConfig.builder().clientId(t.getAppId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).ignoreCheckState(t.getIgnoreCheckState()).build(), STATE_CACHE);

    public static final Function<SocialLoginConfigProperties, AuthRequest> dingtalkFunction = (t) -> new AuthDingTalkRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);

    public static final Function<SocialLoginConfigProperties, AuthRequest> baiduFunction = (t) -> new AuthBaiduRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);

    public static final Function<SocialLoginConfigProperties, AuthRequest> githubFunction = (t) -> new AuthGithubRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> giteeFunction = (t) -> new AuthGiteeRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> weiboFunction = (t) -> new AuthWeiboRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> codingFunction = (t) -> new AuthCodingRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> oschinaFunction = (t) -> new AuthOschinaRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    // 支付宝在创建回调地址时，不允许使用localhost或者127.0.0.1，所以这儿的回调地址使用的局域网内的ip
    public static final Function<SocialLoginConfigProperties, AuthRequest> alipay_walletFunction = (t) -> new AuthAlipayRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), t.getAlipayPublicKey(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> qqFunction = (t) -> new AuthQqRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> wechat_openFunction = (t) -> new AuthWeChatOpenRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> taobaoFunction = (t) -> new AuthTaobaoRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> douyinFunction = (t) -> new AuthDouyinRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> linkedinFunction = (t) -> new AuthLinkedinRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> microsoftFunction = (t) -> new AuthMicrosoftRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> renrenFunction = (t) -> new AuthRenrenRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);

    public static final Function<SocialLoginConfigProperties, AuthRequest> stack_overflowFunction = (t) -> new AuthStackOverflowRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).stackOverflowKey("").build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> huaweiFunction = (t) -> new AuthHuaweiRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> wechat_enterpriseFunction = (t) -> new AuthWeChatEnterpriseQrcodeRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).agentId("").build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> gitlabFunction = (t) -> new AuthGitlabRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);

    public static final Function<SocialLoginConfigProperties, AuthRequest> wechat_mpFunction = (t) -> new AuthWeChatMpRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
    public static final Function<SocialLoginConfigProperties, AuthRequest> aliyunFunction = (t) -> new AuthAliyunRequest(AuthConfig.builder().clientId(t.getClientId()).clientSecret(t.getAppSecret()).redirectUri(t.getRedirectUri()).build(), STATE_CACHE);
}
